<template>
	<view>
		<view>
			<form @submit="formSubmit">
				<view class="uni-form-item uni-column">
					<view class="title">姓名</view>
					<input class="uni-input" name="name" type="text"/>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">密码</view>
					<input class="uni-input" name="password" type="password"/>
				</view>
				<view class="uni-btn-v">
					<button form-type="submit">登录</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script setup>
	const formSubmit = (e) => {
		uni.request({
			url: 'http://101.42.158.48:3000/rxh/deng',
			method: 'POST',
			data: {
				name:e.detail.value.name,
				password:e.detail.value.password
			},
			success: res => {
				// console.log(res.data,'登录成功')
				uni.setStorage({
					key: 'idss',
					data: res.data.user._id,
				})
				uni.setStorage({
					key: 'avatar',
					data: res.data.user.avatar,
				})
				uni.switchTab({
					url: '/pages/mine/mine'
				});
				e.detail.value.name=''
				e.detail.value.password=''
			},
			fail: () => {},
			complete: () => {}
		});
	}
</script>

<style>
	.uni-form-item{
		width: 100%;
		display: flex;
		align-items: center;
	}
	.uni-form-item .title {
		padding: 20rpx 0;
	}
	.uni-input{
		width: 70%;
		border: 1px solid black;
	}
</style>